package common.web.http;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.PropertyPreFilter;

/**
 * 自定义属性过滤器
 * 
 * @author MRJ
 *
 */
public class CustomPropertyFilter implements PropertyPreFilter {

	Map<String, Set<String>> filterProperties = new HashMap<String, Set<String>>();

	/* (non-Javadoc)
	 * @see com.alibaba.fastjson.serializer.PropertyPreFilter#apply(com.alibaba.fastjson.serializer.JSONSerializer, java.lang.Object, java.lang.String)
	 */
	@Override
	public boolean apply(JSONSerializer serializer, Object object, String name) {
		for (Entry<String, Set<String>> entry : filterProperties.entrySet()) {
			if(entry.getKey().equals(object.getClass().getName())) {
				Set<String> value = entry.getValue();
				if (value.contains(name)) {
					return false;
				}
			}
		}
		return true;
	}

	public Map<String, Set<String>> getFilterProperties() {
		return filterProperties;
	}

	public void setFilterProperties(Map<String, Set<String>> filterProperties) {
		this.filterProperties = filterProperties;
	}

}
